﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.IO;
using MatchBilingualSent;

namespace SplitSentPair
{
    class Program
    {
        static void Main(string[] args)
        {
            MultiSplit ms = new MultiSplit();
            MatchSent match = new MatchSent();
            WordSeg.WordSeg wordseg = new WordSeg.WordSeg();
            wordseg.LoadLexicalDict("ChineseDictionary.txt");
            match.Initialize(wordseg, 0.123);

            StreamWriter sw_best = new StreamWriter("best_sent.txt");
            for (int i = 0; i <= 12; i++)
            {
                StreamReader sr = new StreamReader(i.ToString() + ".txt");
                StreamWriter sw = new StreamWriter(i.ToString() + ".txt.other");
                while (sr.EndOfStream == false)
                {
                    string strEnglish = sr.ReadLine();
                    strEnglish = " " + strEnglish + " ";
                    strEnglish = strEnglish.Replace(" it s ", " it's ");

                    string strChinese = sr.ReadLine();
                    sr.ReadLine();
                    List<SentenceToken> stList;

                    if (strEnglish.Length + strChinese.Length > 256)
                    {
                        //strEnglish = "I'm glad to hear it .";
                        //strChinese = "听到这个消息我很高兴.";

                        stList = ms.DoMultiSplit(strEnglish + "\n" + strChinese);
                    }
                    else
                    {

                        stList = new List<SentenceToken>();
                        SentenceToken st = new SentenceToken();
                        st.strSent = strEnglish;
                        st.type = OutputType.E_TYPE;
                        stList.Add(st);

                        st = new SentenceToken();
                        st.strSent = strChinese;
                        st.type = OutputType.C_TYPE;
                        stList.Add(st);
                    }

                    List<SentencePair> spList;
                    spList = match.Match(stList);
                    foreach (SentencePair sp in spList)
                    {
                        sw_best.WriteLine(sp.strLine1);
                        sw_best.WriteLine(sp.strLine2);
                        sw_best.WriteLine();
                    }
                    if (spList.Count == 0)
                    {
                        sw.WriteLine(strEnglish);
                        sw.WriteLine(strChinese);
                        sw.WriteLine();
                    }

                }
                sr.Close();
            }
            sw_best.Close();
        }
    }
}
